testrunner.define({
  
  classname : "songfacts.song",

  
  setUp : function()
  {
    this.testee = new lesp.songfacts.Song({
      "dist" : 0, 
      "href" : "/detail.php?id=4383", 
      "name" : "Disposition"
    });
  },
  
  testGetComments : function() 
  {
    this.assertTrue(this.testee instanceof lesp.songfacts.Song);
    
    this.testee.attach("loaded", (function()
    {
      this.resume(function()
      {
        var comments = this.testee.getComments();
        
        this.assertArray(comments);
        this.assertEquals(17, comments.length);
        
        comments.forEach(function(comment)
        {
          this.assertTrue(qx.lang.String.contains(comment, '<span class="commentext">'));
          this.assertTrue(qx.lang.String.contains(comment, '<span class="name">'));
        }, this);
      }, this);
    }).bind(this));
    
    this.testee.attach("notLoaded", (function()
    {
      this.resume(function()
      {
        this.fail("Song not loaded");
      }, this);
    }).bind(this));
    
    this.wait(15 * 1000);
  },

  testGetFacts : function()
  {
    this.assertTrue(this.testee instanceof lesp.songfacts.Song);
    
    this.testee.attach("loaded", (function()
    {
      this.resume(function()
      {
        var facts = this.testee.getFacts();
        
        this.assertArray(facts);
        this.assertEquals(1, facts.length);
        
        this.assertEquals(0, facts[0].indexOf("Although this has very few words"));
        this.assertEquals(facts[0].length - "miami, FL)".length, facts[0].lastIndexOf("miami, FL)"));
      }, this);
    }).bind(this));
    
    this.testee.attach("notLoaded", (function()
    {
      this.resume(function()
      {
        this.fail("Song not loaded");
      }, this);
    }).bind(this));
    
    this.wait(15 * 1000);    
  }
  
});

testrunner.define({
  
  classname : "songfacts.manager",

  
  testLoad : function() 
  {
    var testee   = new lesp.songfacts.Manager("Tool", "Disposition");
    var renderer = new lesp.songfacts.Renderer(testee);
    var counter  = 0;
    
    testee.attach("found", (function()
    {
      this.assertEquals(0, counter);
      counter += 1;
      
      this.assertEquals("/detail.php?id=4383", testee._songUrlQuery);
    }).bind(this));
    
    testee.attach("loaded", (function(target, song)
    {
      this.assertEquals(1, counter);
      this.resume(function()
      {
        this.assertTrue(song instanceof lesp.songfacts.Song);
        this.assertTrue(song.getComments().length >= 17);
        this.assertEquals(1, renderer.render().length);
      }, this);
    }).bind(this));
    
    testee.attach("failed", (function(song)
    {
      this.resume(function()
      {
        this.fail("Manager failed");
      }, this);
    }).bind(this));
    
    this.wait(15 * 1000);    
  }

});